#include "animal-base.h"
#include <string.h>
#include <stdio.h>

//定义类信号
enum {
	DRINK_BASE_SIGNAL 	= 0,
	EAT_BASE_SIGNAL 	= 1,
	RUN_BASE_SIGNAL 	= 2,
	LAST_BASE_SIGNAL //惯例，动态表示信号个数
};
static int basesignals[LAST_BASE_SIGNAL];

//
G_DEFINE_TYPE(AnimalBase,animal_base,G_TYPE_OBJECT);

//pBase init
static void animal_base_init(AnimalBase *pBase) {
	printf("animal_base_init.\n");
}
//unref object
static void animal_base_class_destroy(GObject *object) {
	printf("animal_base_class_destroy.\n");
}
//free object
static void animal_base_class_finalize(GObject *object) {
	printf("animal_base_class_finalize.\n");
}
 
static void animal_base_drink(AnimalBase *pBase) {
	printf("animal_base_drink[%p] class[%p].\n",pBase,ANIMAL_BASE_GET_CLASS(pBase));
}
 
static void animal_base_eat(AnimalBase *pBase) {
	printf("animal_base_eat[%p].\n",pBase);
}
 
static void animal_base_run(AnimalBase *pBase) {
	printf("animal_base_run[%p].\n",pBase);
}
 
static void animal_base_class_init(AnimalBaseClass *pBaseClass) {
	G_OBJECT_CLASS(pBaseClass)->finalize = animal_base_class_finalize;
	G_OBJECT_CLASS(pBaseClass)->dispose  = animal_base_class_destroy;
	pBaseClass->drinkwater  			 = animal_base_drink;
	pBaseClass->eat  			 		 = animal_base_eat;
	pBaseClass->run  			 		 = animal_base_run;
	
	basesignals[DRINK_BASE_SIGNAL] = g_signal_new ("basedrink",
                      G_TYPE_FROM_CLASS (pBaseClass),
                      G_SIGNAL_RUN_LAST,
					  G_STRUCT_OFFSET (AnimalBaseClass, drinkwater),
                      NULL,
                      NULL,
                      g_cclosure_marshal_VOID__VOID,
                      G_TYPE_NONE, 0);
	printf("animal_base_class_init.\n");
}
 
void send_base_drink_signal(AnimalBase *pBase) {
	g_signal_emit (pBase, basesignals[DRINK_BASE_SIGNAL], 0);
}
